const path = require("path");
module.exports = (app) => {
  const koaNunjucks = require("koa-nunjucks-2");
  const koaStatic = require("koa-static");
  app.use(koaStatic(path.resolve(process.cwd(), "./app/public")));
  app.use(
    koaNunjucks({
      ext: "tpl",
      path: path.resolve(process.cwd(), "./app/public"),
      nunjucksConfig: {
        noCache: true,
        trimBlocks: true,
      },
    })
  );
  // 引入body 解析中间件
  const koaBodyParse = require("koa-bodyparser");
  app.use(
    koaBodyParse({
      formLimit: "1000mb",
      enableTypes: ["from", "json", "text"],
    })
  );
  // 异常补获
  app.use(app.middlewares.errorHandle);
  // 签名验证
  app.use(app.middlewares.apiSignVerify);
  // api参数校验
  app.use(app.middlewares.apiParamsVerify);
};
